#Kiwi Editor is a framework for building WYSIWYG web editors.
#Copyright (C) 2011  Roosevelt de Lima Sardinha

#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

#Contact the author at roosevelt1@gmail.com (Roosevelt) 


# == Schema Information
# Schema version: 20101204202135
#
# Table name: eo_types
#
#  id         :integer         not null, primary key
#  type_name  :string(255)
#  created_at :datetime
#  updated_at :datetime
#

class EoType < ActiveRecord::Base
  has_many :eos, :dependent => :destroy
  has_many :assoc_profile_types, :dependent => :destroy
  has_many :profiles, :through => :assoc_profile_types
  
  def self.create_type(type_name)
    if (!EoType.type_exists?(type_name))
        eo_type = EoType.new
        eo_type.type_name = type_name
        eo_type.save
    end
  end
  
  def self.type_exists?(type_name)
      EoType.find_by_type_name(type_name)  
  end  
  
  def to_hash
    as_json = ActiveSupport::JSON

    eo_type_data = {}
    eo_type_data["id"] = self.id
    eo_type_data["name"] = self.type_name
    
    return eo_type_data
  end  
end

 